package Interface.Requete;

import java.awt.GridLayout;
import java.util.ArrayList;
import java.util.List;

import javax.swing.JPanel;

import Controleur.ControleurGestionRequetes;
import Interface.InterfaceObservable;

public class PanelRequete extends JPanel implements InterfaceObservable{

	private List<InterfaceTableRequete> listeTableRequete;
	private InterfaceTitre interfaceTitre;
	private ControleurGestionRequetes controleur;
	public PanelRequete()
	{

		controleur = ControleurGestionRequetes.getInstance();
		this.setLayout(new GridLayout(1,2));
		interfaceTitre = new InterfaceTitre();
		this.add(interfaceTitre);
		listeTableRequete = new ArrayList<InterfaceTableRequete>();
		listeTableRequete.add(new InterfaceTableRequete());
		listeTableRequete.add(new InterfaceTableRequete());
		listeTableRequete.add(new InterfaceTableRequete());
		listeTableRequete.add(new InterfaceTableRequete());
		listeTableRequete.add(new InterfaceTableRequete());
		
		this.add(listeTableRequete.get(0));
		this.add(listeTableRequete.get(1));
		this.add(listeTableRequete.get(2));
		this.add(listeTableRequete.get(3));
		this.add(listeTableRequete.get(4));
		this.setVisible(true);
	}
	public void executeRequete() {
		List<String> select = new ArrayList<String>();
		List<String> from = new ArrayList<String>();
		controleur.initRequete();
		for(int i=0;i<this.listeTableRequete.size();i++)
		{
			String nomSelect = this.listeTableRequete.get(i).getSelectAttribut(); 
			String nomFrom = this.listeTableRequete.get(i).getFromTable(); 
			
			if ((!nomSelect.equals("") )&& (!nomFrom.equals("") ))
			{
				controleur.ajouterTableRequete(nomSelect,nomFrom,this.listeTableRequete.get(i).getOu());
			}
		}
		controleur.getContrainte();
		controleur.executer();
	}
	
	public void addTable(String nomTable) {
		for(int i=0;i<this.listeTableRequete.size();i++)
		{
			this.listeTableRequete.get(i).addTable(nomTable);
			
		}
	}
	public void deleteTable(String nomTable) {
		for(int i=0;i<this.listeTableRequete.size();i++)
		{
			this.listeTableRequete.get(i).deleteTable(nomTable);
			
		}
	}
	public void updateTable(String nomTable) {
		for(int i=0;i<this.listeTableRequete.size();i++)
		{
			this.listeTableRequete.get(i).updateTable(nomTable);
			
		}
	}
	
}
